<?php
/**
 * @file designcontroller.php $
 * @author yuebin (yuebin@haibao.com) $
 * @date 2015年12月4日 11:26:38 $
 * @brief  $
 */
namespace haibao\cms\business\control\pc\channel\design;

use haibao\cms\model\filter\Article as ArticleFilter;
use haibao\cms\model\filter\ArticleProperty as ArticlePropertyFilter;
use haibao\cms\model\filter\imagecollective\ImageCollective as ImageCollectiveFilter;
use haibao\cms\model\filter\imagecollective\ImageCollectiveProperty as ImageCollectivePropertyFilter;
use haibao\cms\model\filter\designer\Designer as DesignerFilter;
use haibao\cms\model\filter\designer\DesignerRelBrand as DesignerRelBrandFilter;
use haibao\cms\model\filter\designer\DesignerProperty as DesignerPropertyFilter;
use haibao\cms\model\filter\designer\InformationDesigner as InformationDesignerFilter;
use haibao\cms\data\control\DesignController as DesignControllerData;
use haibao\cms\model\data\designer\Designer as DesignerModel;
use haibao\frame\data\query\Condition;
use haibao\frame\data\query\Pager;
use haibao\cms\model\data\InformationAmerican;
use haibao\cms\business\control\pc\entity\ArticleEntity;
use haibao\cms\business\control\pc\action\ArticleAction;
use haibao\cms\business\control\ArticleController;
use haibao\cms\business\control\PublicController as PublicControllerBusiness;

class DesignController extends \haibao\cms\business\control\pc\channel\ChannelController{
	
	const PAGE_SIZE = 30;
	const DESIGN_A_Z_OTHER_LETTER = 'OTHER';
	const FACE_CHINESE_ORIGIN = \haibao\cms\model\data\designer\Designer::FACE_CHINESE_ORIGIN;
	const FACE_CHINA = \haibao\cms\model\data\designer\Designer::FACE_CHINA;
	private static $_instance;
	public $designData;
	public function __construct($updateTime='',$controlId='',$isPublish=''){
		if(!$this->designData instanceof DesignControllerData){
			$this->designData = new DesignControllerData;
		}
		parent::__construct($updateTime,$controlId,$isPublish);
	}
	
	public static function getDesignInstance(){
		if(!(self::$_instance instanceof self)){
			self::$_instance = new self;
		}
		return self::$_instance;
	}
	
	public function getDesignerIds(){
	    return $this->designData->getDesignIds();
	}
	
	/**
	 * 获取设计师最新的动态数据
	 */
	public function getDesignDynamic(){
		$articleEntity = new ArticleEntity();
        $articleEntity->setLevel(3);
        $articleEntity->setBigLevel(7);
        $articleEntity->setLimit(4);
        $articleEntity->setIsProImage(true);
        $articleEntity->setIsLeftJoinTag(true);
        $articleEntity->setIsPrimaryTag(false);
        $articleEntity->setIsConditionTag(true);
        $articleEntity->setIsReturnTag(true);
        $articleEntity->setIsImageColl(true);
        $articleEntity->setTagIds(11195);//11195
        $articleEntity->setOrderByNew(true,'desc');
        $articleEntity->setSource(__CLASS__);
        $articleEntity->setIsDebug(false);
        $articleEntity->setIsOnlyReturnPrimaryTag(true);
        $articleEntity->setProImageLevel(\haibao\cms\model\data\ArticleProImage::Level_FOUR);
        $this->parseTagId(11195,2848);
        $this->articleAction->initArticleAction();
        $this->articleAction->setArticleEnity($articleEntity);
        list($articles,$imageColls) = $this->articleAction->getListForNew();
        $mergeData = $this->mergeData($articles['list'],$imageColls['list'],4);
        $articleList = array();
        foreach($mergeData as $key=>$article){
            $articleArr = $article->toArray();
            $articleArr['SiteType'] = $article->SiteType;
            if($article->SiteType == ArticleController::INFO_TYPE_ARTICLE){	
            	$tag = $articles['tag'];
            	$articleTag = $articles['articleTag'];
            	$articleArr['PublishTime'] = date('Y-m-d H:i:s',strtotime($article->PublishTime->format('Y-m-d H:i:s')));
            	$articleArr['Channel'] = self::getArticleUrl($article->PublishId,$articleTag[$article->Id]['ParentId']);
            	$articleArr['TagName'] = $tag[$articleTag[$article->Id]['TagId']]['TagName'];
            	$articleArr['TagUrl'] = $tag[$articleTag[$article->Id]['TagId']]['Url'];
            	$articleArr['ProImage'] =  isset($articles['proImage'][$article->Id][\haibao\cms\model\data\ArticleProImage::Level_SIX])?$articles['proImage'][$article->Id][\haibao\cms\model\data\ArticleProImage::Level_SIX]:
            	(isset($articles['proImage'][$article->Id][\haibao\cms\model\data\ArticleProImage::Level_ZERO])?$articles['proImage'][$article->Id][\haibao\cms\model\data\ArticleProImage::Level_ZERO]:'');
            }else{
            	$articleArr['PublishId'] = $article->Id;
            	$tag = $imageColls['tag'];
            	$collTag = $imageColls['collTag'];
            	$articleArr['PublishTime'] = date('Y-m-d H:i:s',strtotime($article->PublishTime->format('Y-m-d H:i:s')));
            	$articleArr['Channel'] = self::getArticleUrl($article->Id,$collTag[$article->Id]['ParentId'],ArticleController::INFO_TYPE_IMAGE);
            	$articleArr['TagName'] = $tag[$collTag[$article->Id]['TagId']]['TagName'];
            	$articleArr['TagUrl'] = $tag[$collTag[$article->Id]['TagId']]['Url'];
            	$articleArr['ProImage'] =  isset($imageColls['proImage'][$article->Id][\haibao\cms\model\data\ArticleProImage::Level_SIX])?$imageColls['proImage'][$article->Id][\haibao\cms\model\data\ArticleProImage::Level_SIX]:
            	(isset($imageColls['proImage'][$article->Id][\haibao\cms\model\data\ArticleProImage::Level_ZERO])?$imageColls['proImage'][$article->Id][\haibao\cms\model\data\ArticleProImage::Level_ZERO]:'');
            }
            array_push($articleList,$articleArr);
        }
        $articleList =  json_decode(json_encode($articleList));
        return $articleList;
	}
	
	/**
	 * 大牌设计师
	 */
	public function getBigDesign($designCategory = null){
		$finalDatalList = array();
		list($articleDesignerArr,$articleProImages,$articleTags,$designTagIdArr,$imageIdOneArr) = $this->getArticleDesigner($designCategory);
		list($imageCollDesignerArr,$imageCollProImages,$imageCollTags,$imageIdTwoArr) = $this->getImageCollDesigner($designCategory,$designTagIdArr);
		if($articleDesignerArr || $imageCollDesignerArr){
			$topTag = self::getTopTags();
			$imageList = \haibao\cms\business\ImageLibrary::getImagesById(array_merge($imageIdOneArr,$imageIdTwoArr));
			$imageArr = array();
			foreach($imageList as $key=>$image){
				$imageArr[$image->Id] = $image->Filename;
			}
			$mergeData = array_merge($articleDesignerArr,$imageCollDesignerArr);
			if($mergeData){
			    foreach($mergeData as $key=>$data){
			        if($data->InfoType == 1){
			            $tagId[] = $data->Info->ArticleProperty->TagId;
			        }else{
			            $tagId[] = $data->Info->ImageCollectivePro->TagId;
			        }
			    }
			    $tagInfo = PublicControllerBusiness::getTagInfoById($tagId);
			    foreach($mergeData as $key=>$data){
			        $temp = array();
			        $temp['DesignerId'] = $data->DesignInfo->Id;
			        $temp['NameCN'] = $data->DesignInfo->NameCN;
			        $temp['NameEN'] = $data->DesignInfo->NameEN;
			    
			        $temp['PublishTime'] = $data->PublishTime->format('Y-m-d H:i:s');
			        $temp['DesignerImage'] = isset($imageArr[$data->DesignInfo->ImgId])?$imageArr[$data->DesignInfo->ImgId]:'';
			        $temp['DesignerUrl'] = \haibao\classlibrary\Config::getConfig(\haibao\classlibrary\Config::CLASSLIBRARY_CONFIG_HOST_DESIGNER).'/designer/'.$data->DesignInfo->TopicId.'/';
			        $parentId = 6;
			        $temp['InfoTitle'] = $data->Info->Title;
			        $temp['InfoShortTitle'] = $data->Info->ShortTitle;
			        $temp['InfoId'] = $data->InfoId;
			        $temp['InfoType'] = $data->InfoType;
			        if($data->InfoType == \haibao\cms\model\data\designer\InformationDesigner::INFO_TYPE_ARTICLE){
			            $temp['TagName'] = $tagInfo[$data->Info->ArticleProperty->TagId]['TagName'];
			            $temp['TagUrl'] = $tagInfo[$data->Info->ArticleProperty->TagId]['Url'];
			    
			            if(isset($articleTags[$data->InfoId]['ParentId'])){
			                $parentId = $articleTags[$data->InfoId]['ParentId'];
			            }
			            $temp['InfoUrl'] = $topTag[$parentId]['channelurl'].'/article/'.$data->Info->PublishId.'.htm';
			            $temp['InfoProImage'] = isset($articleProImages[$data->InfoId][\haibao\cms\model\data\ArticleProImage::Level_FIVE])?$articleProImages[$data->InfoId][\haibao\cms\model\data\ArticleProImage::Level_FIVE]:
			            (isset($articleProImages[$data->InfoId][\haibao\cms\model\data\ArticleProImage::Level_ZERO])?$articleProImages[$data->InfoId][\haibao\cms\model\data\ArticleProImage::Level_ZERO]:'');
			        }else{
			            $temp['TagName'] = $tagInfo[$data->Info->ImageCollectivePro->TagId]['TagName'];
			            $temp['TagUrl'] = $tagInfo[$data->Info->ImageCollectivePro->TagId]['Url'];
			    
			            if(isset($imageCollTags[$data->InfoId]['ParentId'])){
			                $parentId = $imageCollTags[$data->InfoId]['ParentId'];
			            }
			            $temp['InfoUrl'] = \haibao\classlibrary\Config::getConfig(\haibao\classlibrary\Config::CLASSLIBRARY_CONFIG_HOST_PIC).'/'. $topTag[$parentId]['channel'].'/pics/'.$data->InfoId.'.html';
			            $temp['InfoProImage'] = isset($imageCollProImages[$data->InfoId][\haibao\cms\model\data\ArticleProImage::Level_FIVE])?$imageCollProImages[$data->InfoId][\haibao\cms\model\data\ArticleProImage::Level_FIVE]:
			            (isset($imageCollProImages[$data->InfoId][\haibao\cms\model\data\ArticleProImage::Level_ZERO])?$imageCollProImages[$data->InfoId][\haibao\cms\model\data\ArticleProImage::Level_ZERO]:'');
			        }
			        array_push($finalDatalList,$temp);
			    }
			}
		}
		if($finalDatalList){
		    $finalDatalList = array_slice($finalDatalList,0,3);
		    $temp = array();
		    foreach ($finalDatalList as $val) {
		        $temp[] = $val['PublishTime'];
		    }
		    array_multisort($temp, SORT_DESC, $finalDatalList);
		}
		return $finalDatalList;
		//print_R($finalDatalList);exit;
	}
	
	public function getArticleDesigner($designCategory){
		$articleIdArr = $articleDesignerArr = $designTagIdArr = $imageIdArr = array();
		$articleFilter = new ArticleFilter();
		$designerFilter = new DesignerFilter();
		$designerInformationFilter = new InformationDesignerFilter();
		$articlePropertyFilter = new ArticlePropertyFilter();
		$articleTagFilter = new \haibao\cms\model\filter\ArticleTag();
		$articleFilter->select(array(
				ArticleFilter::CONDITION_FIELD_NAME_ID,
				ArticleFilter::CONDITION_FIELD_NAME_ARTICLE_PUBLISHID,
				ArticleFilter::CONDITION_FIELD_NAME_TITLE,
				ArticleFilter::CONDITION_FIELD_NAME_SHORTTITLE,
		));
		$designerFilter->select(array(
				DesignerFilter::CONDITION_FIELD_NAME_TAG_ID,
				DesignerFilter::CONDITION_FIELD_NAME_NAMECN,
				DesignerFilter::CONDITION_FIELD_NAME_NAMEEN,
				DesignerFilter::CONDITION_FIELD_NAME_TOPIC_ID,
				DesignerFilter::CONDITION_FIELD_NAME_IMGID,
				DesignerFilter::CONDITION_FIELD_NAME_ID,
		));
		$designerInformationFilter->select(array(
				InformationDesignerFilter::CONDITION_FIELD_NAME_INFO_ID,
				InformationDesignerFilter::CONDITION_FIELD_NAME_INFO_TYPE,
				InformationDesignerFilter::CONDITION_FIELD_NAME_DESIGNER_TAG_ID,
		        InformationDesignerFilter::CONDITION_FIELD_NAME_PUBLISH_TIME,
		));
		$articlePropertyFilter->select(array(
				ArticlePropertyFilter::CONDITION_FIELD_NAME_CLICK_NUM
		));
		
		$articleTagFilter->select(array(
		    $articleTagFilter::CONDITION_FIELD_NAME_TAG_ID,
		    $articleTagFilter::CONDITION_FIELD_NAME_IS_PRIMAIY,
		));
		
		//$articleFilter->innerJoin($articleTagFilter,null,ArticleFilter::CONDITION_FIELD_NAME_ID,$articleTagFilter::CONDITION_FIELD_NAME_ARTICLE_ID,$articleFilter::CONDITION_FIELD_NAME_ARTICLE_TAG,false);
		
		
		$designerInformationFilter->limit(0,6);
		$designerInformationFilter->order(ArticleFilter::CONDITION_FIELD_NAME_PUBLISHTIME,false);
		$designerInformationFilter->innerJoin($designerFilter,null,InformationDesignerFilter::CONDITION_FIELD_NAME_DESIGNER_TAG_ID,DesignerFilter::CONDITION_FIELD_NAME_TAG_ID,InformationDesignerFilter::CONDITION_FIELD_NAME_DESIGN_INFO,false);
		$designerInformationFilter->innerJoin($articleFilter,null,InformationDesignerFilter::CONDITION_FIELD_NAME_INFO_ID,ArticleFilter::CONDITION_FIELD_NAME_ID,InformationDesignerFilter::CONDITION_FIELD_NAME_INFO,false);
		$designerInformationFilter->innerJoin($articleTagFilter,$articleFilter,ArticleFilter::CONDITION_FIELD_NAME_ID,$articleTagFilter::CONDITION_FIELD_NAME_ARTICLE_ID,ArticleFilter::CONDITION_FIELD_NAME_ARTICLE_PROPERTY,false);
		$articleTagFilter->where($articleTagFilter::CONDITION_FIELD_NAME_TAG_ID, Condition::CONDITION_NOTEQUAL, 11195);
		//$articleTagFilter->where($articleTagFilter::CONDITION_FIELD_NAME_IS_PRIMAIY, Condition::CONDITION_EQUAL, 1);
		$articleTagFilter->where($articleTagFilter::CONDITION_FIELD_NAME_PARENT_ID, Condition::CONDITION_EQUAL, 2848);
		$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_LEVEL, Condition::CONDITION_GREATEREQUAL, 3);
		$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_STATUS, Condition::CONDITION_EQUAL, 0);
		$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_PUBLISHED, Condition::CONDITION_EQUAL, 1);
		if($designCategory){
			$designerFilter->where(DesignerFilter::CONDITION_FIELD_NAME_CATEGORY_TAGID,Condition::CONDITION_EQUAL,$designCategory);
		}else{
			$designerFilter->where(DesignerFilter::CONDITION_FIELD_NAME_CATEGORY_TAGID,Condition::CONDITION_IS_NULL,null);
		}
		$designerInformationFilter->where(InformationDesignerFilter::CONDITION_FIELD_NAME_INFO_TYPE,Condition::CONDITION_EQUAL,\haibao\cms\model\data\designer\InformationDesigner::INFO_TYPE_ARTICLE);
		$articleDesignerList = $this->designData->getAll($designerInformationFilter);
		if($articleDesignerList){
			foreach($articleDesignerList as $articleDesigner){
				$articleDesignerArr[$articleDesigner->InfoId] = $articleDesigner;
				array_push($articleIdArr,$articleDesigner->InfoId);
				array_push($designTagIdArr,$articleDesigner->DesignerTagId);
				array_push($imageIdArr,$articleDesigner->DesignInfo->ImgId);
			}
			$articleControl = \haibao\cms\business\control\ArticleController::initArticleControl();
			$articleProImages = $articleControl->getArticleProImage($articleIdArr, array(\haibao\cms\model\data\ArticleProImage::Level_FIVE));
			$articleTags = $articleControl->getArticleTagByArticleId($articleIdArr);
			$articleTagArr = array();
			foreach($articleIdArr as $key=>$articleId){
			    $articleTagArr[$articleId] = \haibao\cms\business\Article::getArticleTagsByArticleId($articleId);
			}
			if($articleTagArr){
			    foreach($articleTagArr as $key=>$val){
			        foreach($val as $k=>$v){
			            if($v == 11195){
			                unset($articleDesignerArr[$key]);
			            }
			        }
			        
			    }
			}
			return array($articleDesignerArr,$articleProImages,$articleTags,$designTagIdArr,$imageIdArr);
		}else{
			return array($articleDesignerArr,array(),array(),$designTagIdArr,$imageIdArr);
		}
	}
	
	public function getImageCollDesigner($designCategory,$designTagIdArr = array()){
		$imageCollIdArr = $imageCollDesignerArr = $imageIdArr = array();
		$imageCollFilter = new ImageCollectiveFilter();
		$designerFilter = new DesignerFilter();
		$designerInformationFilter = new InformationDesignerFilter();
		$imageCollPropertyFilter = new ImageCollectivePropertyFilter();
		$imageCollTagFilter = new \haibao\cms\model\filter\imagecollective\ImageCollectiveTag();
		$imageCollFilter->select(array(
				ImageCollectiveFilter::CONDITION_FIELD_NAME_ID,
				ImageCollectiveFilter::CONDITION_FIELD_NAME_TITLE,
		));
		$designerFilter->select(array(
				DesignerFilter::CONDITION_FIELD_NAME_TAG_ID,
				DesignerFilter::CONDITION_FIELD_NAME_NAMECN,
				DesignerFilter::CONDITION_FIELD_NAME_NAMEEN,
				DesignerFilter::CONDITION_FIELD_NAME_TOPIC_ID,
				DesignerFilter::CONDITION_FIELD_NAME_IMGID,
				DesignerFilter::CONDITION_FIELD_NAME_ID,
		));
		$designerInformationFilter->select(array(
				InformationDesignerFilter::CONDITION_FIELD_NAME_INFO_ID,
				InformationDesignerFilter::CONDITION_FIELD_NAME_INFO_TYPE,
		        InformationDesignerFilter::CONDITION_FIELD_NAME_PUBLISH_TIME
		));
		$imageCollPropertyFilter->select(array(
				ImageCollectivePropertyFilter::CONDITION_FIELD_NAME_CLICK_NUM
		));
		
		$imageCollTagFilter->select(array(
		    $imageCollTagFilter::CONDITION_FIELD_NAME_TAG_ID,
		    $imageCollTagFilter::CONDITION_FIELD_NAME_TAG_ISPRIMAIY
		));
		
		$designerInformationFilter->limit(0,6);
		$designerInformationFilter->order(ImageCollectiveFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHTIME,false);
		$designerInformationFilter->innerJoin($designerFilter,null,InformationDesignerFilter::CONDITION_FIELD_NAME_DESIGNER_TAG_ID,DesignerFilter::CONDITION_FIELD_NAME_TAG_ID,InformationDesignerFilter::CONDITION_FIELD_NAME_DESIGN_INFO,false);
		$designerInformationFilter->innerJoin($imageCollFilter,null,InformationDesignerFilter::CONDITION_FIELD_NAME_INFO_ID,ImageCollectiveFilter::CONDITION_FIELD_NAME_ID,InformationDesignerFilter::CONDITION_FIELD_NAME_INFO,false);
		$designerInformationFilter->innerJoin($imageCollTagFilter,$imageCollFilter,ImageCollectiveFilter::CONDITION_FIELD_NAME_ID,$imageCollTagFilter::CONDITION_FIELD_NAME_TAG_COLLECTIVE_ID,ImageCollectiveFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PRO,false);
		$imageCollFilter->where(ImageCollectiveFilter::CONDITION_FIELD_NAME_STATUS, Condition::CONDITION_EQUAL, 1);
		$imageCollFilter->where(ImageCollectiveFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHED, Condition::CONDITION_EQUAL, 1);
		$imageCollFilter->where(ImageCollectiveFilter::CONDITION_FIELD_NAME_LEVEL, Condition::CONDITION_GREATEREQUAL, 3);
		if($designCategory){
			$designerFilter->where(DesignerFilter::CONDITION_FIELD_NAME_CATEGORY_TAGID,Condition::CONDITION_EQUAL,$designCategory);
		}else{
			$designerFilter->where(DesignerFilter::CONDITION_FIELD_NAME_CATEGORY_TAGID,Condition::CONDITION_IS_NULL,null);
		}
		if($designTagIdArr){
			$designerInformationFilter->where(InformationDesignerFilter::CONDITION_FIELD_NAME_DESIGNER_TAG_ID,Condition::CONDITION_NOTIN,$designTagIdArr);
		}
		$designerInformationFilter->where(InformationDesignerFilter::CONDITION_FIELD_NAME_INFO_TYPE,Condition::CONDITION_EQUAL,\haibao\cms\model\data\designer\InformationDesigner::INFO_TYPE_PIC);
		$imageCollTagFilter->where($imageCollTagFilter::CONDITION_FIELD_NAME_TAG_ID, Condition::CONDITION_NOTEQUAL, 11195);
		//$imageCollTagFilter->where($imageCollTagFilter::CONDITION_FIELD_NAME_TAG_ISPRIMAIY, Condition::CONDITION_EQUAL, 1);
		$imageCollTagFilter->where($imageCollTagFilter::CONDITION_FIELD_NAME_TAG_PARENTID, Condition::CONDITION_EQUAL, 2848);
		$imageCollDesignerList = $this->designData->getAll($designerInformationFilter);
		if($imageCollDesignerList){
			foreach($imageCollDesignerList as $imageCollDesigner){
				$imageCollDesignerArr[$imageCollDesigner->InfoId] = $imageCollDesigner;
				array_push($imageCollIdArr,$imageCollDesigner->InfoId);
				array_push($imageIdArr,$imageCollDesigner->DesignInfo->ImgId);
			}
			$imageCollControl = \haibao\cms\business\control\ArticleController::initArticleControl();
			$imageCollProImages = $imageCollControl->getCollProImage($imageCollIdArr, array(\haibao\cms\model\data\ArticleProImage::Level_FIVE));
			$imageCollTags = $imageCollControl->getCollTagByCollId($imageCollIdArr);
			
			$imageCollTagArr = array();
			$imageCollTagArr = \haibao\cms\business\imagecollective\ImageCollective::getImageCollectiveTagById($imageCollIdArr);
			
			if($imageCollTagArr){
			    foreach($imageCollTagArr as $key=>$val){
			        foreach($val as $k=>$v){
			            if($v == 11195){
			                unset($imageCollDesignerArr[$key]);
			            }
			        }
			    }
			}
			return array($imageCollDesignerArr,$imageCollProImages,$imageCollTags,$imageIdArr);
		}else {
			return array($imageCollDesignerArr,array(),array(),$imageIdArr);
		}
		
	}
	
	/**
	 * 报友最关注 手动/自动数据相结合
	 */
	public function getDesignerByAttention($designIds = array(),$removeDesignerId = array(),$limit = null){
		$designerPropertyFilter = new DesignerPropertyFilter();
		$designerFilter = new DesignerFilter();
		$designerFilter->select(array(
				DesignerFilter::CONDITION_FIELD_NAME_TAG_ID,
				DesignerFilter::CONDITION_FIELD_NAME_NAMECN,
				DesignerFilter::CONDITION_FIELD_NAME_NAMEEN,
				DesignerFilter::CONDITION_FIELD_NAME_TOPIC_ID,
				DesignerFilter::CONDITION_FIELD_NAME_IMGID,
				DesignerFilter::CONDITION_FIELD_NAME_ID,
				DesignerFilter::CONDITION_FIELD_NAME_ISBRAND,
		));
		if($designIds){
		    shuffle($designIds);
		    $designIds = array_slice($designIds,0,10);
			$designerFilter->where(DesignerRelBrandFilter::CONDITION_FIELD_NAME_ID,Condition::CONDITION_IN,$designIds);
		}
		if($removeDesignerId){
			$designerFilter->where(DesignerRelBrandFilter::CONDITION_FIELD_NAME_ID,Condition::CONDITION_NOTIN,$removeDesignerId);
		}
		$designerList = $this->designData->getAll($designerFilter);
		$designerList = array_slice($designerList,0,$limit);
		//print_r($designerList);exit;
		return $designerList;
	}
		
	/**
	 * @param Array $condition 查询条件
	 * @return Object $designerList 设计师列表
	 */
	public function getDesignerList($condition,$isGetAll = true){
		// 根据$confition 封装query filter
		if(!$isGetAll){
			$dataList = $this->getDesignerListByCondition($condition);
		}else{
			$dataList = \haibao\www\cache\Library::getSearchCache('DESIGNER');
			if(isset($dataList)){
				$dataList = json_decode($dataList,true);
			}else{
				$dataList = $this->getDesignListAZ();
				\haibao\www\cache\Library::setSearchCache('DESIGNER',json_encode($dataList));
			}
		}
		return $dataList;
	}
	
	public function getDesignListAZ(){
		$designerList = $pager  = array();
		$preFiveDesignerImgIdArr = $preFiveDesignerIdArr = $allDesignerTagIdArr = array();
		// 获取明星A_Z数据
		$count = 0;
		for($start=ord("A");$start<=ord("Z");$start++){
			$letterDeisgnList = $this->designData->getDesignListByLetter(chr($start));
			if($letterDeisgnList){
				$preFiveDesigner = array_slice($letterDeisgnList, 0,5);
				$nextNineDesigner = array_slice($letterDeisgnList, 5,9);
				$designerList[chr($start)]['five'] = $preFiveDesigner;
				$designerList[chr($start)]['nine'] = $nextNineDesigner;
				$count += count($letterDeisgnList);
				$preFiveDesignerImgIdArr = array_merge($preFiveDesignerImgIdArr,array_map(function($element){return $element['ImgId'];}, $preFiveDesigner));
				$preFiveDesignerIdArr = array_merge($preFiveDesignerIdArr,array_map(function($element){return $element['Id'];}, $preFiveDesigner));
				$allDesignerTagIdArr =  array_merge($allDesignerTagIdArr,array_map(function($element){return $element['TagId'];}, $letterDeisgnList));
			}
		}
		$letterDeisgnList = $this->designData->getDesignListByLetter(self::DESIGN_A_Z_OTHER_LETTER);
		if($letterDeisgnList){
			$preFiveDesigner = array_slice($letterDeisgnList, 0,5);
			$nextNineDesigner = array_slice($letterDeisgnList, 5,9);
			$designerList['其他']['five'] = $preFiveDesigner;
			$designerList['其他']['nine'] = $nextNineDesigner;
			$count += count($letterDeisgnList);
			$preFiveDesignerImgIdArr = array_merge($preFiveDesignerImgIdArr,array_map(function($element){return $element['ImgId'];}, $preFiveDesigner));
			$preFiveDesignerIdArr = array_merge($preFiveDesignerIdArr,array_map(function($element){return $element['Id'];}, $preFiveDesigner));
			$allDesignerTagIdArr =  array_merge($allDesignerTagIdArr,array_map(function($element){return $element['TagId'];}, $letterDeisgnList));
		}
		$designTagInfoList = \haibao\cms\business\Tag::getTagsById($allDesignerTagIdArr);
		$designImageArr = \haibao\cms\business\ImageLibrary::getImageUrlById($preFiveDesignerImgIdArr);
		//$designFansCount = $this->designData->getDesignerFansCount($preFiveDesignerIdArr);
		if($designerList){
			foreach($designerList as $letter=>$design){
				$preFiveStarList = $designerList[$letter]['five'];
				$nextNineStarList = $designerList[$letter]['nine'];
				foreach($preFiveStarList as $key=>$preFiveDesign){
					if(isset($designImageArr[$preFiveDesign['ImgId']])){
						$preFiveStarList[$key]['ImageUrl'] = self::getImageLink($designImageArr[$preFiveDesign['ImgId']],140,140);
					}
					if(isset($designTagInfoList[$preFiveDesign['TagId']])){
						$preFiveStarList[$key]['DesignUrl'] = \haibao\classlibrary\Config::getConfig(\haibao\classlibrary\Config::CLASSLIBRARY_CONFIG_HOST_DESIGNER).$designTagInfoList[$preFiveDesign['TagId']]['Url'];
					}
					if(!isset($preFiveStarList[$key]['FansCount'])){
						$preFiveStarList[$key]['FansCount'] = 0;
					}
				}
				foreach($nextNineStarList as $key=>$nextNineDesign){
					if(isset($designTagInfoList[$nextNineDesign['TagId']])){
						$nextNineStarList[$key]['DesignUrl'] = \haibao\classlibrary\Config::getConfig(\haibao\classlibrary\Config::CLASSLIBRARY_CONFIG_HOST_DESIGNER).$designTagInfoList[$nextNineDesign['TagId']]['Url'];
					}
				}
				$designerList[$letter]['five'] = $preFiveStarList;
				$designerList[$letter]['nine'] = $nextNineStarList;
			}
		}
		return array($designerList,$pager);
		//return $designerList;
	}
	
	public function getDesignerListByCondition($condition){
		$designerFilter = new DesignerFilter();
		$designerFilter->select(array(
				DesignerFilter::CONDITION_FIELD_NAME_ID,
				DesignerFilter::CONDITION_FIELD_NAME_TAG_ID,
				DesignerFilter::CONDITION_FIELD_NAME_NAMECN,
				DesignerFilter::CONDITION_FIELD_NAME_NAMEEN,
				DesignerFilter::CONDITION_FIELD_NAME_GENDER,
				DesignerFilter::CONDITION_FIELD_NAME_PINYINEN,
				DesignerFilter::CONDITION_FIELD_NAME_CREATETIME,
				DesignerFilter::CONDITION_FIELD_NAME_REGION,
				DesignerFilter::CONDITION_FIELD_NAME_IMGID,
		))->limit(0,30);
		
		$designerPropertyFilter = new DesignerPropertyFilter();
		$designerPropertyFilter->select(array(
				DesignerPropertyFilter::CONDITION_FIELD_NAME_FANSNUM
		));
		
		$designerFilter->leftJoin($designerPropertyFilter,null,$designerFilter::CONDITION_FIELD_NAME_ID,$designerPropertyFilter::CONDITION_FIELD_NAME_DESIGNER_ID,$designerFilter::CONDITION_FIELD_NAME_FANSCOUNT,false);
		
		//状态
		if($condition['state']){
			if($condition['state'] == DesignerModel::SITE_STATE_FANS_MORE){
				$designerFilter->order(DesignerPropertyFilter::CONDITION_FIELD_NAME_FANSNUM,false,$designerPropertyFilter);
			}else{
				$designerFilter->order(DesignerFilter::CONDITION_FIELD_NAME_CREATETIME,false);
			}
		}

		//性别
		if($condition['position']){
			$designerFilter->where(DesignerFilter::CONDITION_FIELD_NAME_GENDER,Condition::CONDITION_EQUAL,(int)$condition['position']);
		}
		
		//面孔
		if($condition['face']){
			$designerFilter->where(DesignerFilter::CONDITION_FIELD_NAME_CATEGORY_TAGID,Condition::CONDITION_EQUAL,(int)$condition['face']);
		}
		
		//地域
		if($condition['area']){
			$designerFilter->where(DesignerFilter::CONDITION_FIELD_NAME_REGION,Condition::CONDITION_LIKE,'%['.$condition['area'].']%');
		}
		
		//身份
		if($condition['oppcupation']){
			$designerFilter->where(DesignerFilter::CONDITION_FIELD_NAME_IDENTITY,Condition::CONDITION_LIKE,'%['.$condition['oppcupation'].']%');
		}
		
		//品牌
		if($condition['brands']){
			$designerBrandFilter = new DesignerRelBrandFilter();
			$designerBrandFilter->select(array(
					DesignerRelBrandFilter::CONDITION_FIELD_NAME_DESIGNER_ID,
					DesignerRelBrandFilter::CONDITION_FIELD_NAME_BRAND_ID,
					DesignerRelBrandFilter::CONDITION_FIELD_NAME_REL_TYPE
			));
			$designerBrandFilter->where($designerBrandFilter::CONDITION_FIELD_NAME_BRAND_ID,Condition::CONDITION_EQUAL,(int)$condition['brands']);
			$designerFilter->leftJoin($designerBrandFilter,null,$designerFilter::CONDITION_FIELD_NAME_ID,$designerBrandFilter::CONDITION_FIELD_NAME_DESIGNER_ID,$designerFilter::CONDITION_FIELD_NAME_BRANDS,false);
		}
		
		if($condition['letter']){
			if($condition['letter'] === self::DESIGN_A_Z_OTHER_LETTER){
				$enRange = array();
				for($i=ord('A');$i<=ord('Z');$i++){
					array_push($enRange,chr($i));
				}
				$designerFilter->where(DesignerFilter::CONDITION_FIELD_NAME_PINYINEN,Condition::CONDITION_NOTIN,$enRange);
			}else{
				$designerFilter->where(DesignerFilter::CONDITION_FIELD_NAME_PINYINEN,Condition::CONDITION_EQUAL,$condition['letter']);
			}
		}
		$designerFilter->where(DesignerFilter::CONDITION_FIELD_NAME_STATUS,Condition::CONDITION_EQUAL,\haibao\cms\model\data\designer\Designer::CELEBRITY_ENABLE);
		$designerFilter->setPager(new Pager(self::PAGE_SIZE,$condition['page']));
		$pager = $designerFilter->getPager();
		$designerList = \haibao\cms\business\Designer::getDesignerByFilter($designerFilter, false);
		$designTagInfoList = $designTagIdArr = $designImageIdArr = array();
		if($designerList){
			foreach($designerList as $design){
				array_push($designTagIdArr,$design->TagId);
				$designImageIdArr[$design->TagId] = $design->ImgId;
			}
			$designImageArr = \haibao\cms\business\ImageLibrary::getImageUrlById($designImageIdArr);
			$designTagInfoList = \haibao\cms\business\Tag::getTagsById($designTagIdArr);
			foreach($designerList as $design){
				if(isset($designImageArr[$design->ImgId])){
					$design->ImageUrl = self::getImageLink($designImageArr[$design->ImgId],140,140);
				}
				if(isset($designTagInfoList[$design->TagId])){
					$design->DesignUrl = \haibao\classlibrary\Config::getConfig(\haibao\classlibrary\Config::CLASSLIBRARY_CONFIG_HOST_DESIGNER).$designTagInfoList[$design->TagId]['Url'];
				}
			}
		}

		return array($designerList,$pager);
		//return $designerList;
	}
}